function ajax(obj) {
    if(!obj.success || typeof obj.success != "function")return console.error("success is wrong!!");
    if(!obj.url || typeof obj.url != "string")return console.error("url is wrong!!");
    obj.data = obj.data || {};
    obj.type = obj.type || "get"; //请求类型

    var xhr;
    if(window.XMLHttpRequest){
        xhr = new XMLHttpRequest()
    }else{
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }

    var params = [];
    for(var i in obj.data){
        params.push(i+"="+obj.data[i]);
    }
    var sendData = params.join("&");
    
    if(obj.type.toUpperCase() == "GET"){
        xhr.open("get",obj.url + "?" + sendData,true);
        xhr.send();
    }else{
        xhr.open("post",obj.url,true);
        xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xhr.send(sendData);
    }

    xhr.onreadystatechange = function(){
        if(xhr.readyState == 4){
            if(xhr.status==200){
                obj.success(xhr.responseText)
            }else{
                obj.error&&typeof obj.error=="function"&&obj.error("你错了");
            }
        }
    };
}